<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <myinput
          placeholder="手机号码"
          class="input"
          :rules="/^1[0-9]{4,10}$/"
          err_message="手机号码格式不正确"
          v-model="user.username"
        /><myinput
          placeholder="昵称"
          class="input"
          :rules="/^[0-9a-zA-Z\u4e00-\u9fa5]{2,6}$/"
          err_message="昵称格式不正确"
          v-model="user.nickname"
        /><myinput
          placeholder="密码"
          class="input"
          type="password"
          :rules="/^[0-9a-zA-Z]{3,12}$/"
          err_message="密码格式不正确"
          v-model="user.password"
        />
      </div>
      <p class="tips">
        有账号？
        <a href="#/login" class="">去登录</a>
      </p>
      <mybutton type="success" @click="register">注册</mybutton>
    </div>
  </div>
</template>

<script>
import myinput from "@/components/myinput";
import mybutton from "@/components/mybutton";
import { userRegister } from "@/api/user";
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
        nickname: "",
      },
    };
  },
  components: {
    myinput,
    mybutton,
  },
  methods: {
    register() {
      userRegister(this.user)
        .then((res) => {
          if (res.data.message == "注册成功") {
            this.$router.push("/login");
          }
          this.$toast.success(res.data.message);
        })
        .catch((err) => {
          this.$toast.success(res.data.message);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
</style>